package com.xzc.java8.A_lambda.lambda5;

import com.xzc.java8.A_lambda.lambda0.Apple;

import java.util.Comparator;

/**
 * 简化lambda，用类型推理系统
 */
public class ComparatorTest {

    public static String getWeightApple(Apple a1, Apple a2, Comparator<Apple> comparator) {
        return comparator.compare(a1, a2) > 0 ? a1.getName() : a2.getName();
    }

    public static void main(String[] args) {
        Apple a1 = new Apple();
        a1.setName("bigger");
        a1.setWeight(50);

        Apple a2 = new Apple();
        a2.setName("smaller");
        a2.setWeight(10);

        System.out.println(getWeightApple(a1, a2, (Apple a, Apple b) -> a.getWeight() - b.getWeight()));
        System.out.println(getWeightApple(a1, a2, (a, b) -> a.getWeight() - b.getWeight()));
        System.out.println(getWeightApple(a1, a2, Comparator.comparingInt(Apple::getWeight)));
    }

}
